

$(".TrialNavLi").bind("click",function(){ //顶部导航滑动效果
    $(this).addClass("TrialNavOn").siblings().removeClass("TrialNavOn");
})

$(".trialStatusLi").bind("click",function(){ //主体部分导航滑动效果
    $(this).addClass("trialStatusOn").siblings().removeClass("trialStatusOn");
})

//懒加载
var page=1;
var num= 4;
var trialIsLoad = true;

$(window).scroll(function () {
    var lineH = $('.footer').offset().top;//获取滚动加载提示的分割线的距离文档顶部的距离

    var clientH = $(window).height();//clientH: 窗口的高度

    var scrollH = $(this).scrollTop();//scrollH: 滚动条在Y轴上的滚动过距离。
    if((scrollH+clientH)>=(lineH-100)){
        if(!trialIsLoad) return;
        trialload();

    }
});



trialload();

function trialload() {  //定义一个加载数据的方法
    trialIsLoad = false;
    $.ajax({
        url: "/trialdata",
        method: "get",
        dataType: "json",
        data:{
            page:page,
            num:num,
        },
        success: function (res) {
            // console.log(res);
            num++;
            page++;

            var trialStr=" ";
            // var eTag1=[];
            $.each(res,function(index,item){
                var eTag1='';
                if(item.eTag1!==null){ //数据不为null显示，为null不显示
                    eTag1= '<span class="discount">'+item.eTag1+'</span>';
                }

                trialStr+='<div class="trialItem">\n'+
                    '<a href="http://www.jiguo.com/event/index/3633.html" target="_blank">\n'+
                    '    <div class="trialItemBox">\n'+
                    '        <div class="trialItemImg">\n'+
                    '            <span class="tag">首发</span>\n'+
                    '           <img class="lazy" src='+item.imgUrl+'/>\n'+
                    '        </div>\n'+
                    '        <div class="trialItemTxtBox">\n'+
                    '            <div class="trialItemTxt">\n'+
                    '                <h4>'+item.title+'</h4>\n'+
                    '                <div class="tips">\n'+
                    '                    <span class="free">'+item.eTag0+'</span>\n'+eTag1+
                    '                </div>\n'+
                    '                <div class="joinNum">\n'+
                    '                    <span class="num left">\n'+
                    '                        <font>'+item.peopleNum+'</font>参与\n'+
                    '                    </span>\n'+
                    '                    <span class="days right"></span>\n'+
                    '                </div>\n'+
                    '                <div class="trialItemTxtHide">\n'+
                    '                    <div class="trialItemTxtHideCell">\n'+
                    '                        <span class="left">'+item.otherTag0+'</span>\n'+
                    '                        <span class="right">'+item.otherTag1+'</span>\n'+
                    '                    </div>\n'+
                    '                    <div class="trialItemTxtHideCell">\n'+
                    '                        <span class="left">'+item.otherTag2+'</span>\n'+
                    '                        <span class="right">'+item.otherTag3+'</span>\n'+
                    '                    </div>\n'+
                    '                    <div class="trialItemTxtHideCell">\n'+
                    '                        <span class="left">'+item.otherTag4+'</span>\n'+
                    '                        <span class="right">'+item.otherTag5+'</span>\n'+
                    '                    </div>\n'+
                    '                </div>\n'+
                    '            </div>\n'+
                    '        </div>\n'+
                    '    </div>\n'+
                    '</a></div>'


            })
            $(".trialList").append(trialStr);

            trialIsLoad = true;
            // 懒加载
            $(".trialItemImg img").lazyload({
                placeholder: "/static/img/timg.gif",
                effect: "fadeIn",
                threshold: 100,
                event: "scroll",
                container: $(".trialItem"),
                failurelimit: 1
            });
        },
        error: function (err) {
            console.log(err);
        }

    })

}
